package com.jiuyi.controller;

import com.jiuyi.common.R;
import com.jiuyi.entity.Employee;
import com.jiuyi.service.Impl.EmployeeServiceImpl;
import com.jiuyi.vo.AdminAddEmployeeVo;
import com.jiuyi.vo.AdminSelectEmployeeByIdVo;
import com.jiuyi.vo.AdminSelectEmployeeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * DATA: 2022/10/17
 * Author: 晨夕
 */
@RestController
@RequestMapping("employee")
public class EmployeeController {

    @Autowired
    private EmployeeServiceImpl employeeServiceImpl;

    /**
     * 登录
     */
    @PostMapping("/login")
    public R<Employee> login(HttpServletRequest request, @RequestBody Employee employee){
        return employeeServiceImpl.login(request,employee);
    }

    /**
     * 登出
     */
    @PostMapping("/logout")
    public R<Employee> logout(HttpServletRequest request){
        return employeeServiceImpl.logout(request);
    }

    /**
     * 添加
     */
    @PostMapping
    public R addEmployee(HttpServletRequest request,@RequestBody Employee employee){
        return employeeServiceImpl.addEmployee(request,employee);
    }

    /**
     * 查询
     */
    @GetMapping("/page")
    public R<AdminSelectEmployeeVo> selectEmployee(int page,int pageSize,String name){
        return employeeServiceImpl.selectEmployee(page,pageSize,name);
    }

    /**
     * 修改
     */
    @PutMapping
    public R updateEmployee(HttpServletRequest request,@RequestBody Employee employee){
        return employeeServiceImpl.updateEmployee(request, employee);
    }

    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public R<AdminSelectEmployeeByIdVo> selectEmployeeById(@PathVariable("id") Long id){
        return employeeServiceImpl.selectEmployeeById(id);
    }
}
